<?php
$cs = Yii::app()->clientScript;
$cs->registerScript(__CLASS__.'#UpdateAlias', "
jQuery('#Vocabulary_name').bind('keyup change', function(){
    var text = jQuery(this).val();
    var alias = text
                .toLowerCase() // change everything to lowercase
                .replace(/^\s+|\s+$/g, '') // trim leading and trailing spaces        
                .replace(/[_|\s]+/g, '-') // change all spaces and underscores to a hyphen
                .replace(/[^a-z0-9\-_]+/g, '') // remove all non-alphanumeric characters except the hyphen
                .replace(/[-]+/g, '-') // replace multiple instances of the hyphen with a single instance
                .replace(/^-+|-+$/g, '') // trim leading and trailing hyphens                
                ;
    jQuery('#Vocabulary_alias').val(alias);
});
");
?>
<div class="form wide">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'vocabulary-form',
	'enableAjaxValidation'=>false,
)); ?>

	<?php echo $form->errorSummary($model); ?>

    <?php if ($model->isNewRecord === false):?>
    <div class="row">
        <label>&nbsp;</label>
        <?php echo CHtml::link($model->properties_form_id ? 'Update Properties' : 'Add Properties', array(
            '/Cms/admin/widget/editForm',
            'id'=>$model->properties_form_id,
            'module'=>$model->module,
            'type'=>$model->alias,
        ));?>
    </div>
    <?php endif;?>

    <?php if (! $model->IsNewRecord) echo $form->hiddenField($model, "id") ; ?>
	<div class="row">
		<?php echo $form->labelEx($model,'name'); ?>
		<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'name'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'alias'); ?>
		<?php echo $form->textField($model,'alias',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'alias'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'description'); ?>
		<?php echo $form->textArea($model,'description',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'description'); ?>
	</div>

    <div class="row">
        <?php echo $form->labelEx($model,'module'); ?>
        <?php echo $form->dropDownList($model,'module', $modules, array('prompt'=>'system'));?>
        <?php echo $form->error($model,'module'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'state'); ?>
        <?php echo $form->dropDownList($model,'state', $model->stateOptions); ?>
        <?php echo $form->error($model,'state'); ?>
    </div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->
